package test.com.db.server;

import test.com.db.server.FakeClient;

import java.io.*;
import java.net.Socket;

public class HundredsOfFakeClients {

    public static final int SND_PER_HIST = -500;
    public static final int NUMBER_OF_CLIENTS = 500;
    public static final int SLEEP_TIME = 14000;

    public static void main(String... args) {
        FakeClient[] clients = new FakeClient[NUMBER_OF_CLIENTS];
        for (int i = 0; i < NUMBER_OF_CLIENTS; ++i) {
            clients[i] = null;
            Socket socket = null;
            try {
                socket = new Socket("127.0.0.1", 1234);
                ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
                ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
                clients[i] = new FakeClient(in, out);
            } catch (IOException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }
        for (int i = 0; i < NUMBER_OF_CLIENTS; ++i) {
            if (clients[i] != null) {
                clients[i].start();
            }
        }
        try {
            Thread.currentThread().sleep(10000);
        } catch (InterruptedException e1) {
            System.err.println("no more sleep");
        }
        for (int i = 0; i < NUMBER_OF_CLIENTS; ++i) {
            if (clients[i] != null) {
                clients[i].interrupt();
            }
        }

    }
}
